import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:dio/adapter.dart';
import 'dart:io';
import 'ShareHandle.dart';
import 'String+extension.dart';

class Util {
  static const TextStyle tinyBlack =
      TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Colors.black);
  static const TextStyle smallBlack =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.black);
  static const TextStyle middleBlack =
      TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: Colors.black);
  static const TextStyle bigBlack =
      TextStyle(fontSize: 50, fontWeight: FontWeight.bold, color: Colors.black);

  static const TextStyle tinyWhite =
      TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Colors.white);
  static const TextStyle tinyNormalWhite =
      TextStyle(fontSize: 14, color: Colors.white);
  static const TextStyle smallWhite =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white);
  static const TextStyle middleWhite =
      TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: Colors.white);

  static const TextStyle tinyWhite3 = TextStyle(
      fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xff888888));

  static const TextStyle smallRed =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red);
  static const TextStyle middleRed =
      TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: Colors.red);
  static const TextStyle bigRed =
      TextStyle(fontSize: 50, fontWeight: FontWeight.bold, color: Colors.red);

  static const TextStyle smallGreen3 =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Util.green3);
  static const TextStyle smallBlue3 =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Util.blue3);

  static const TextStyle smallGreen =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: green);
  static const TextStyle smallBrown =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: brown);
  static const TextStyle tinyBrown =
      TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: brown);

  static const TextStyle smallOrange =
      TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: orange1);
  static const TextStyle middleOrange =
      TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: orange1);
  static const TextStyle bigOrange =
      TextStyle(fontSize: 50, fontWeight: FontWeight.bold, color: orange1);

  static const TextStyle tinyPurple =
      TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: purple3);

  static ButtonStyle noPadding =
      ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.zero));

  static const String afterLoginNotification = "afterLoginNotification";
  static const String logoutNotification = "logoutNotification";
  static const String linkChangedNotification = "linkChangedNotification";
  static const String userinfoChangedNotification =
      "userinfoChangedNotification";

  static const Color dark = Color(0xff3075a1);
  static const Color white1 = Color(0xffffff30);
  static const Color white2 = Color(0xb0ffffff);
  static const Color white3 = Color(0xffdbdbdb);
  static const Color bar = Color(0xffffffff);
  static const Color green = Color(0xff007e8a);
  static const Color yellow1 = Color(0xffFFF9B3);
  static const Color orange1 = Color(0xffeea039);
  static const Color brown = Color(0xff79512a);
  static const Color green1 = Color(0xffd6eede);
  static const Color green2 = Color(0xff8dbf9c);
  static const Color green3 = Color(0xff507b5c);
  static const Color green4 = Color(0xffb3e9b1);
  static const Color green5 = Color(0xff3f8e45);
  static const Color blue1 = Color(0xffd3eaf7);
  static const Color blue2 = Color(0xff50a4f8);
  static const Color blue3 = Color(0xff4581cd);
  static const Color blue4 = Color(0xffc0e6f6);
  static const Color white4 = Color(0xfff4f4f4);
  static const Color purple1 = Color(0xffcec3e7);
  static const Color purple2 = Color(0xffa282eb);
  static const Color purple3 = Color(0xff5e2c8b);
  static const Color red1 = Color(0xfff8d1c4);
  static const Color red2 = Color(0xffe7632a);
  static const Color red3 = Color(0xffe188ba);

  static const String version2 = "1.1";
  static const String version = "v1.1";
  static Future<Response<dynamic>> dio(String url,
      {Map<String, dynamic> dic = const {}, String method = "post"}) {
    var dio = Dio();
    dio.options.responseType = ResponseType.plain;
    dio.options.headers["Authorization"] =
        "Basic clJUYm1uN2l6eWRRQXJSY2pBdWcrbThGTURMbHlwZ0U0dHNndkxCOEJ3OjEyMzQ1Ng==";
    if (ShareHandle.shared.proxy.isNotEmpty) {
      (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
          (HttpClient client) {
        client.findProxy = (uri) {
          // 'PROXY localhost:8888'
          return ShareHandle.shared.proxy;
        };
        return null;
      };
    }
    UtilLog(url.withHost());
    UtilLog(dic.toString());
    if (method == 'post') {
      return dio.post(url.withHost(), data: FormData.fromMap(dic));
    } else {
      return dio.get(url.withHost(), queryParameters: dic);
    }
  }
}
